<?php
// 主页数据处理页面
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
//设置默认时区
date_default_timezone_set('PRC');
$now_date = date('Y-m-d H:i:s', time());
$start_data = date('Y-m-d 00:00:00');
$y_start_data = date('Y-m-d 00:00:00', strtotime('-1 day'));
$y_stop_date = date('Y-m-d 23:59:59', strtotime('-1 day'));
//平台报修任务总数量查询
$sql_1 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request ";
$result_1 = mysqli_query($conn_DB, $sql_1);
if($result_1){
    $row = mysqli_fetch_object($result_1);
    //平台报修任务总数量
    $all_recording = $row->c;
}else{
    $all_recording = 'search_wrong';
}

//累计完成任务总数量查询
$sql_2 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request WHERE fix_status = '2' ";
$result_2 = mysqli_query($conn_DB, $sql_2);
if($result_2){
    $row = mysqli_fetch_object($result_2);
    //累计完成任务总数量
    $all_finish = $row->c;
}else{
    $all_finish = 'search_wrong';
}

//总完修比率
$all_finish_rate = round($all_finish/$all_recording*100,2)."%";

//今日报修任务数量查询
$sql_3 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request WHERE fix_sendtime < '".$now_date."' AND fix_sendtime > '".$start_data."'";
$result_3 = mysqli_query($conn_DB, $sql_3);
if($result_3){
    $row = mysqli_fetch_object($result_3);
    //今日报修任务数量
    $today_recording = $row->c;
}else{
    $today_recording = 'search_wrong';
}

//今日维修数量查询
$sql_4 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request WHERE fix_status = '2' AND fix_endtime < '".$now_date."' AND fix_endtime > '".$start_data."'";
$result_4 = mysqli_query($conn_DB, $sql_4);
if($result_4){
    $row = mysqli_fetch_object($result_4);
    //今日维修数量
    $today_finish = $row->c;
}else{
    $today_finish = 'search_wrong';
}

//昨日报修数量查询
$sql_5 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request WHERE fix_sendtime < '".$y_stop_date."' AND fix_sendtime > '".$y_start_data."'";
$result_5 = mysqli_query($conn_DB, $sql_5);
if($result_5){
    $row = mysqli_fetch_object($result_5);
    //昨日报修数量
    $yesterday_recording = $row->c;
}else{
    $yesterday_recording = 'search_wrong';
}

//报修数量较昨日增长
if(($today_recording - $yesterday_recording) > 0){
    $class = 'main-div-item-num green';
}else{
    $class = 'main-div-item-num red';
}
$record_increase = "<p class='".$class."'>".($yesterday_recording - $today_recording)."</p>";

//昨日维修数量查询
$sql_6 = "SELECT COUNT(*) AS c FROM tb_fixinfo_request WHERE fix_status = '2' AND fix_sendtime < '".$y_stop_date."' AND fix_sendtime > '".$y_start_data."'";
$result_6 = mysqli_query($conn_DB, $sql_6);
if($result_6){
    $row = mysqli_fetch_object($result_6);
    //昨日维修数量
    $yesterday_finish = $row->c;
}else{
    $yesterday_finish = 'search_wrong';
}

//维修数量较昨日增长
if(($today_finish - $yesterday_finish) > 0){
    $class = 'main-div-item-num  green';
}else{
    $class = 'main-div-item-num red';
}
$finish_increase = "<p class='".$class."'>".($today_finish - $yesterday_finish)."</p>";

